<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_hader" th:content="${_csrf.headerName}"/>
    <title>库存管理</title>
    <!--<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}"/>-->
    <!--<script th:src="@{/jquery/jquery-3.0.0.min.js}" ></script>-->
    <!--<script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>-->
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" th:href="@{/css/tooltips/iziToast.css}"/>
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap-datetimepicker.min.css}"/>
    <script th:inline="javascript">
        $(function(){
            $('.form_datetime').datetimepicker({
                language: 'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                forceParse: 1,
                showMeridian: 1
            });
            //获取上一个链接
            $("#preUrl").attr("href",document.referrer);
        });
        function goPrePage(){
            var preMenuUrl = [[${preMenuUrl}]];
            //返回上一页
            window.location.href = preMenuUrl;
        }
        function save(){
            //空值校验
            if(validIsEmpty('productForm')){
                var incomeBill = {};
                $.each($("#productForm input,select,textarea"), function(i, v){
                    var value = v.value;
                    if(value) {
                        incomeBill[v.id] = value ;
                    };
                });
                $.ajax({
                    url:'/incomeBillController/editIncomeBill',
                    type:'POST',
                    data : incomeBill,
                    async : false,
                    success:function (data) {
                        var success = data.success;
                        if(success){
                            //$("#successModel").modal("show");
                            $('#successModel').modal({
                                keyboard: false
                            });
                            $('#successModel .close').hide()
                            //showSuccessMsg(data.msg)
                            window.setTimeout(goPrePage,3000);
                        }else{
                            showErrorMsg(data.msg);
                        }
                    }
                });
            }
        }
    </script>
</head>
<body>
<ol class="breadcrumb">
    <li><a th:href="${preMenuUrl}">库存管理</a></li>
    <li class="active">收入编辑</li>
</ol>
<div class="container" id="indexContainer">
    <div class="row">
        <form class="form-horizontal" role="form" id="productForm">
            <input type="hidden" th:value="${incomeBill.id}" id="id"/>
            <div class="form-group">
                <label for="count" class="col-sm-3 control-label">数量</label>
                <div class="col-sm-6">
                    <input type="number" class="form-control" id="count" th:value="${incomeBill.count}" placeholder="请输入数量"/>
                </div>
            </div>
            <div class="form-group">
                <label for="type" class="col-sm-3 control-label">类型</label>
                <div class="col-sm-6">
                    <select id="type" class="form-control" >
                        <option th:text="收入" th:value="1"></option>
                        <option th:text="支出" th:value="2"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="remark" class="col-sm-3 control-label">备注</label>
                <div class="col-sm-6">
                    <textarea class="form-control" id="remark" th:text="${incomeBill.remark}" rows="3"></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-3"></div>
                <div class="col-sm-9">
                    <button type="button" onclick="save()" class="btn btn-success">保存</button>
                    <button type="button" data-toggle="modal" data-target="#confirmModal" class="btn btn-danger">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="modal fade" data-backdrop="static" id="successModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel" style="color: green;">保存成功,将在3秒后返回商品列表</h4>
            </div>
            <!--<div class="modal-footer">-->
                <!--<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>-->
                <!--<button type="button" class="btn btn-primary">提交更改</button>-->
            <!--</div>-->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">是否放弃编辑</h4>
            </div>
            <!--<div class="modal-body">是否放弃编辑</div>-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="goPrePage();" class="btn btn-primary">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script th:src="@{/js/tooltips/iziToast.min.js}" type="text/javascript"></script>
<script th:src="@{/js/util.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap-datetimepicker.min.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap-datetimepicker.zh-CN.js}"></script>
<script>
    iziToast.settings({
        timeout: 3000,
        // position: 'center',
        // imageWidth: 50,
        pauseOnHover: false,
        // resetOnHover: true,
        close: true,
        progressBar: true,
        // layout: 1,
        // balloon: true,
        // target: '.target',
        // icon: 'material-icons',
        // iconText: 'face',
        // animateInside: false,
        // transitionIn: 'flipInX',
        // transitionOut: 'flipOutX',
    });
    var token = $('meta[name="_csrf"]').attr("content");
    var header = $('meta[name="_csrf_hader"]').attr("content");
    $(document).ajaxSend(function(e,xhr,opt){
        xhr.setRequestHeader(header,token);
    });
</script>
</body>
</html>